<template>
    <div>
        <div class="menuadd">
            <el-button round type="primary" @click="add" plain>添加</el-button>
        </div>
        <el-table style="width: 100%" :data="adminlist">
            <el-table-column prop="id" label="角色编号" width="180"></el-table-column>
            <el-table-column prop="username" label="管理员名称" width="180"></el-table-column>
            <el-table-column prop="rolename" label="角色名称" width="180"></el-table-column>
            <el-table-column prop="status" label="角色状态">
                <template v-slot="$prop">
                    <el-button v-if="$prop.row.status == 1" round type="primary" size="mini" plain>正常</el-button>
                    <el-button v-else round type="warning" size="mini" plain>禁用</el-button>
                </template>
            </el-table-column>

            <el-table-column prop="status" label="操作">
                <template v-slot="$prop">
                    <el-button round type="primary" size="mini" @click="change($prop.row)" plain>编辑</el-button>
                    <el-button round type="danger" size="mini" @click="del($prop.row.id)" v-if="$prop.row.id != 1" plain>
                        删除</el-button>
                </template>

            </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <el-pagination background layout="prev, pager, next" :page-size="1" :total="admintotal"
            @current-change="changepage"></el-pagination>

        <v-dialog :info="info" ref="son" />
    </div>
</template>


<script>
// import { del } from "vue";
import { mapActions, mapState } from 'vuex';
import vDialog from "./dialog.vue"

export default {
    components: {
        vDialog
    },
    computed: {
        ...mapState("admin", ["adminlist", "admintotal"])
    },
    methods: {
        ...mapActions("admin", ["getadminlist", "getadmintotal"]),
        // 新增
        add() {
            this.info.isShow = true
        },
        // 编辑
        change(useradd) {
            console.log(useradd, 1223);
            console.log(this.$refs.son);
            this.info.isShow = true
        },
        // 删除
        del(id) {
            this.$confirms(() => {
                this.$Api.userdelete({ id }).then((res) => {
                    console.log(res, 111111);
                    if (res.code == 200) {
                        this.$message.success(res.msg)
                        this.getadmintotal()
                    } else {
                        this.$message.error(res.msg)
                    }
                })
            })
            console.log(id, "删除");
        },
        // 修改页面
        changepage(page) {
            this.getadminlist({ size: this.size, page });
        }
    },
    mounted() {
        this.getadminlist({ size: this.size, page: this.page });
        this.getadmintotal()
    },
    data() {
        return {
            size: 1,
            page: 1,
            info: {
                isShow: false
            }
        }
    }
}

</script>


<style leng='less' scoped>
.el-pagination {
    float: left;
    margin-top: 10px;
}
</style>